package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/wending/h5/config"
	"net/http"
	"net/url"
)

type GetUserDataApiService service

type GetUserDataRequest struct {
	ctx        context.Context
	ApiService *GetUserDataApiService
	siteId     *uint
	startTime  *uint64
	endTime    *uint64
	page       *uint64
	pageSize   *uint64
	userId     *uint64
	userOpenId *string
}

type GetUserDataResponse struct {
	Code    *int64    `json:"code,omitempty"`
	Message *string   `json:"message,omitempty"`
	Data    *UserData `json:"data,omitempty"`
}

type UserData struct {
	TotalPage *uint64         `json:"totalPage,omitempty"`
	UserList  []*UserDataItem `json:"userData,omitempty"`
}

type UserDataItem struct {
	UserId             *uint64 `json:"userId,omitempty"`
	NickName           *string `json:"nickName,omitempty"`
	Gender             *string `json:"gender,omitempty"`
	UserRegisterTime   *uint64 `json:"userRegisterTime,omitempty"`
	UserFollowed       *uint   `json:"userFollowed,omitempty"`
	FirstFocusTime     *uint64 `json:"firstFocusTime,omitempty"`
	AppId              *string `json:"appId,omitempty"`
	WxMpName           *string `json:"wxMpName,omitempty"`
	WxOpenId           *string `json:"wxOpenId,omitempty"`
	Vip                *uint   `json:"vip,omitempty"`
	VipEndTime         *uint64 `json:"vipEndTime,omitempty"`
	Balance            *uint   `json:"balance,omitempty"`
	HongBao            *uint   `json:"hongbao,omitempty"`
	TotalRechargeMoney *uint64 `json:"totalRechargeMoney,omitempty"`
	TotalRechargeTimes *uint   `json:"totalRechargeTimes,omitempty"`
	LinkId             *uint64 `json:"linkId,omitempty"`
	LinkName           *string `json:"linkName,omitempty"`
	ExternalUserId     *string `json:"externalUserId,omitempty"`
	ThirdCorpId        *string `json:"thirdCorpId,omitempty"`
}

func (r *GetUserDataRequest) SiteId(siteId uint) *GetUserDataRequest {
	r.siteId = &siteId
	return r
}

func (r *GetUserDataRequest) StartTime(startTime uint64) *GetUserDataRequest {
	r.startTime = &startTime
	return r
}

func (r *GetUserDataRequest) EndTime(endTime uint64) *GetUserDataRequest {
	r.endTime = &endTime
	return r
}

func (r *GetUserDataRequest) Page(page uint64) *GetUserDataRequest {
	r.page = &page
	return r
}

func (r *GetUserDataRequest) PageSize(pageSize uint64) *GetUserDataRequest {
	r.pageSize = &pageSize
	return r
}

func (r *GetUserDataRequest) UserId(userId uint64) *GetUserDataRequest {
	r.userId = &userId
	return r
}

func (r *GetUserDataRequest) UserOpenId(userOpenId string) *GetUserDataRequest {
	r.userOpenId = &userOpenId
	return r
}

func (r *GetUserDataRequest) Execute() (*GetUserDataResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *GetUserDataRequest) ConsumerKey(ConsumerKey string) *GetUserDataRequest {
	r.ctx = context.WithValue(r.ctx, config.ConsumerKey, ConsumerKey)
	return r
}

func (r *GetUserDataRequest) SecretKey(SecretKey string) *GetUserDataRequest {
	r.ctx = context.WithValue(r.ctx, config.SecretKey, SecretKey)
	return r
}

func (r *GetUserDataRequest) WithLog(enable bool) *GetUserDataRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *GetUserDataApiService) Get(ctx context.Context) *GetUserDataRequest {
	return &GetUserDataRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *GetUserDataApiService) getExecute(r *GetUserDataRequest) (*GetUserDataResponse, *http.Response, error) {

	cfg := a.client.Cfg
	var (
		localVarPath         = cfg.GetBasePath() + "/dist-api/getUserData"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *GetUserDataResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasReqParam(r.siteId, "SiteId"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	localVarQueryParams.Add("siteid", toString(r.siteId))

	if r.startTime != nil {
		localVarQueryParams.Add("starttime", toString(r.startTime))
	}

	if r.endTime != nil {
		localVarQueryParams.Add("endtime", toString(r.endTime))
	}

	if r.page != nil {
		localVarQueryParams.Add("page", toString(r.page))
	}
	if r.pageSize != nil {
		localVarQueryParams.Add("pageSize", toString(r.pageSize))
	}

	if r.userId != nil {
		localVarQueryParams.Add("userId", toString(r.userId))
	}

	if r.userOpenId != nil {
		localVarQueryParams.Add("useropenid", *r.userOpenId)
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
